package com.tianqu.tms.www.car.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.dto.MarketCarInfoDto;
import com.tianqu.tms.entity.Codes;
import com.tianqu.tms.www.car.actionform.CarPrivilegedCarDetailActionForm;
import com.tianqu.tms.www.car.controller.CarPrivilegedCarDetailUpdateController;
import com.tianqu.tms.www.car.viewhelper.CarPrivilegedCarManageViewHelper;

/**
 * 特权车管理 - 信息录入(修改画面)
 * @author zhao-qc
 *
 */
public class CarPrivilegedCarDetailUpdateAction extends TmsAction {

	private Logger logger = Logger.getLogger(CarPrivilegedCarDetailUpdateAction.class);
	@SuppressWarnings("unchecked")
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		
		CarPrivilegedCarManageViewHelper priviCarViewHelper = new CarPrivilegedCarManageViewHelper();
	    uc.setAttribute(TmsConstants.VIEWHELP, priviCarViewHelper);

	    CarPrivilegedCarDetailUpdateController controller = new CarPrivilegedCarDetailUpdateController();
		controller.execute(uc);
		
		Codes code = Codes.getInstance();
		MarketCarInfoDto marketCarDto = (MarketCarInfoDto)uc.getAttribute(TmsConstants.VIEWHELP);
		CarPrivilegedCarDetailActionForm actionFromFM = (CarPrivilegedCarDetailActionForm)uc.getInputForm();
		if("1".equals(actionFromFM.getFlg())){
			priviCarViewHelper.setLicensePlate(actionFromFM.getLicensePlate());
			priviCarViewHelper.setTempLicensePlate(actionFromFM.getTempLicensePlate());
			priviCarViewHelper.setValidStatus(actionFromFM.getValidStatus());
			priviCarViewHelper.setEndDate(actionFromFM.getEndDate());
			priviCarViewHelper.setRemarks(actionFromFM.getRemarks());
		}else{
			priviCarViewHelper.setLicensePlate(marketCarDto.getLicensePlate());
			priviCarViewHelper.setTempLicensePlate(marketCarDto.getTempLicensePlate());
			priviCarViewHelper.setValidStatus(marketCarDto.getRegisterStatusPri());
			priviCarViewHelper.setEndDate(marketCarDto.getEnterTimeS());
			priviCarViewHelper.setRemarks(marketCarDto.getRemark());
		}
		priviCarViewHelper.setValidStatusList(code.getCodeslistByItemId(Codes.VALIDSTATUS));
		
		
		
		// 直接把list打到前台
		request.setAttribute(TmsConstants.VIEWHELP, priviCarViewHelper);
		
		logger.debug(this.getClass().getName() + "#execute was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
